<h4 class="h4_title">收货人信息<!--{if $visitor.user_id}--><a href="{url app=my_address}" target="_blank">{$lang.manage_address}</a><!--{/if}--></h4>
<div class="blank"></div>
<script type="text/javascript" src="{lib file=mlselection.js}" charset="utf-8"></script>
<script type="text/javascript" src="{lib file=jquery.plugins/jquery.validate.js}" charset="utf-8"></script>
<script type="text/javascript">
var addresses = {$addresses};
$(function(){
    regionInit("region");
    $('#order_form').validate({
        errorPlacement: function(error, element){
            var _message_box = $(element).parent().find('.field_message');
            _message_box.find('.field_notice').hide();
            _message_box.append(error);
        },
        success : function(label){
            label.addClass('validate_right').text('OK!');
        },
        rules : {
            consignee : { required : true },
            region_id : { required : true, min : 2 },
            address   : { required : true },
            phone_mob : { required : check_phone, minlength:11,maxlength:11, digits : true
			   <!--{if !$visitor.user_id}-->
			   ,remote   : {
                    url :'index.php?app=member&act=check_user&ajax=1',
                    type:'get',
                    data:{ user_name : function(){ return $('#phone_mob').val(); }},
                    beforeSend:function(){
                        var _checking = $('#checking_user');
                        _checking.prev('.field_notice').hide();
                        _checking.next('label').hide();
                        $(_checking).show();
                    },
                    complete :function(){
                        $('#checking_user').hide();
                    }
                }
				<!--{/if}-->
			},
			<!--{if !$visitor.user_id}-->
			im_qq     : { required : true , minlength : 5, digits : true },
			<!--{/if}-->			
            phone_tel : { required : check_phone, minlength:6, checkTel : true }
        },
        messages : {
            consignee : { required : '{$lang.consignee_required}' },
            region_id : { required : '{$lang.region_required}', min : '{$lang.region_required}' },
            address   : { required : '{$lang.address_required}' },
            phone_mob : { required : '请填写正确手机号码', minlength: '只能是数字,并且不能少于11位',maxlength: '只能是数字,并且不能大于11位', digits : '{$lang.phone_mob_error}'
			<!--{if !$visitor.user_id}-->
			,remote   : '该手机号已注册账户，<a href="index.php?app=member&act=login">立即登录</a>' 
			<!--{/if}-->
			},
			<!--{if !$visitor.user_id}-->
			im_qq     : { required : '请正确填写QQ号码', minlength : '错误的QQ号码,只能是数字,并且不能少于5位', digits : 'QQ号码只能填写数字' },
			<!--{/if}-->			
            phone_tel : { required : '{$lang.phone_required}', minlength: '{$lang.phone_tel_error}', checkTel : '{$lang.phone_tel_error}' }
        }
    });

});
function check_phone(){
    return ($('#phone_tel').val() == '' && $('#phone_mob').val() == '');
}
function hide_error(){
    $('#region').find('.error').hide();
}
</script>
<!--{if $my_address}-->
<script type="text/javascript">
//<![CDATA[
$(function(){
    $('input[name="address_options"]').click(function(){
        $(this).attr('checked', true);
        $('.address_item').removeClass('selected_address');
        $(this).parent().addClass('selected_address');
		$('input[name="save_address"]').attr("checked",'true');
        set_address();
    });					
    set_address();
});
function set_address(){
    var addr_id = $("input[name='address_options']:checked").val();
    if(addr_id == 0)
    {
        $('#consignee').val("");
        $('#region_name').val("");
        $('#region_id').val("");
        $('#region select').show();
        $("#edit_region_button").hide();
        $('#region_name_span').hide();
        $('#address').val("");
        $('#phone_tel').val("");
        $('#phone_mob').val("");
        $('#address_form').show();
    }else{
        $('#address_form').hide();
        fill_address_form(addr_id);
    }
    sumAllMoney();
}
function fill_address_form(addr_id){
    sumAllMoney();
    var addr_data = addresses[addr_id];
    for(k in addr_data){
        switch(k){
            case 'consignee':
            case 'address':
            case 'email':
            case 'phone_tel':
            case 'phone_mob':
            case 'region_id':
                $("input[name='" + k + "']").val(addr_data[k]);
            break;
            case 'region_name':
                $("input[name='" + k + "']").val(addr_data[k]);
                $('#region select').hide();
                $('#region_name_span').text(addr_data[k]).show();
                $("#edit_region_button").show();
            break;
        }
    }    
}
//]]>
</script>
<!--{foreach from=$my_address item=address name=address_select}-->
<label>
<ul class="receive_add address_item{if $smarty.foreach.address_select.iteration == 1} selected_address{/if}">
<input id="address_{$address.addr_id}" type="radio"{if $smarty.foreach.address_select.iteration == 1} checked="true"{/if} name="address_options" value="{$address.addr_id}" class="radio"/>
{$address.region_name|escape}&nbsp;&nbsp;{$address.address|escape} （{$address.consignee|escape} 收）<!--{if $address.phone_mob}-->{$address.phone_mob}<!--{else}-->{$address.phone_tel}<!--{/if}--> <INPUT id="on_pro_{$address.addr_id}" type="hidden" value="{$address.parents_region_id}">
</ul></label>
<!--{/foreach}-->
<label>
<ul class="new_receive_add address_item">
    <input type="radio" name="address_options" id="use_new_address" value="0" />
    {$lang.use_new_address}
</ul>
</label>
<!--{/if}-->

<ul class="fill_in_content" id="address_form">
<li>
  <p class="title"><font color="red">*</font>{$lang.consignee}：</p>
  <p class="fill_in"><input name="consignee" type="text" class="input_text" id="consignee" /> <span class="field_message explain"><span class="field_notice">{$lang.consignee_desc}</span></span></p>
</li>
<li>
  <p class="title"><font color="red">*</font>{$lang.region}：</p>
  <p class="fill_in"><span id="region"><span style="display:none;" id="region_name_span"></span>
      <select onchange="hide_error();">
      <option value="0">{$lang.select_pls}</option>
      {html_options options=$regions}
      </select>
      <input type="hidden" class="mls_id" name="region_id" id="region_id"/>
      <input type="hidden" name="region_name" class="mls_names" id="region_name"/>
      <input id="edit_region_button" type="button" class="edit_region" value="{$lang.edit}" style="display:none;" />
      <span class="field_message explain"><span class="field_notice">{$lang.region_desc}</span></span></span>
  </p>
</li>
<li>
  <p class="title"><font color="red">*</font>{$lang.address}：</p>
  <p class="fill_in"><input name="address" type="text" class="input_text" id="address" style="width:350px" /> <span class="field_message explain"><span class="field_notice">{$lang.address_desc}</span></span></p>
</li>
<li>
  <p class="title"><font color="red">*</font>{$lang.phone_mob}：</p>
  <p class="fill_in"><input type="text" id="phone_mob" name="phone_mob" class="input_text"/> <span class="field_message explain"><span class="field_notice">请填写手机号码</span><label id="checking_user" class="checking">{$lang.checking}</label></span></p>
</li>
<!--{if !$visitor.user_id}-->
<li>
  <p class="title"><font color="red">*</font>QQ号码：</p>
  <p class="fill_in"><input name="im_qq" type="text" class="input_text" id="im_qq"/> <span class="field_message explain"><span class="field_notice">请填写QQ号码</span></span></p>
</li>  
<!--{/if}-->
<li style="display:none">
  <p class="title">{$lang.phone_tel}：</p>
  <p class="fill_in"><input type="text" name="phone_tel" id="phone_tel" class="input_text" /> <span class="field_message explain"><span class="field_notice">{$lang.phone_tel_desc}</span></span></p>
</li> 
<li>
  <p class="title">&nbsp;</p>
  <p class="fill_in">
    <label><input name="save_address" type="checkbox" id="save_address" value="1" {if !$my_address}checked="checked"{/if}>&nbsp;{$lang.save_address}<span class="explain">&nbsp;(&nbsp;{$lang.save_address_desc}&nbsp;)&nbsp;</span></label>
  </p>
</li>
</ul>